<script src="../../build/linq.js"></script>
<script src="../../build/visualbasic.wasm.js"></script>

<script type="text/javascript">
    var clock = new TypeScript.Benchmark();
    var upbound = 2000000;
    var isPrime2 = WebAssembly.ObjectManager.hashCodeHelper.isPrime;
    var stack1 = [];
    var stack2 = [];
    var a, b;

    console.warn(a = clock.Tick());

    for (var i = 0; i < upbound; i++) {
        if (isPrime2(i)) {
            stack1.push(i);
        }
    }

    console.warn(b = clock.Tick());
    console.warn(b.sinceLastCheck);    

    console.log("==========================================");

    console.warn(a = clock.Tick());

    for (var i = 0; i < upbound; i++) {
        if (isPrime(i)) {
            stack2.push(i);
        }
    }

    console.warn(b = clock.Tick());
    console.warn(b.sinceLastCheck);

    console.log(stack1);
    console.log(stack2);


    function isPrime(value) {
        if (value <= 3) {
            return value >= 2;
        }
        if (value % 2 == 0 || value % 3 == 0) {
            return false
        }
        for (var i = 5; i * i <= value; i += 6) {
            if (value % i == 0 || value % (i + 2) == 0) {
                return false
            }
        }
        return true
    }
</script>